#include "WindForce.h"
#include <ctime>

e3d::physics::WindForce::WindForce( const D3DXVECTOR3& initialForce, const D3DXVECTOR3& changeFactor )
:	Force( initialForce ), 
	m_changeFactor( changeFactor )
{}

void e3d::physics::WindForce::onFrameMove()
{
	srand( static_cast<unsigned int>(time( NULL ) ));

	float forceVecNorm = D3DXVec3Length( &m_force );

	// Alter x and z direction of this force. If the force is a unit vector, 
	// and the change factor is 1.0 the change amount of one component
	// is within [-1;+1]
	m_force.x += m_changeFactor.x * 2.0f * ( 0.5f - ( static_cast<float>( rand() ) / RAND_MAX ) );
	m_force.z += m_changeFactor.z * 2.0f * ( 0.5f - ( static_cast<float>( rand() ) / RAND_MAX ) );
	
	D3DXVec3Normalize( &m_force, &m_force );
	m_force *= forceVecNorm;

	// Update shader variables
	Force::s_forceDirection->SetFloatVectorArray( m_force, m_instanceID, 1 );
}

